//
//  DuanWeiViewController.m
//  Hero
//
//  Created by lanou3g on 16/5/7.
//  Copyright © 2016年 刘永庆. All rights reserved.
//

#import "DuanWeiViewController.h"

@interface DuanWeiViewController ()
@property (weak, nonatomic) IBOutlet UILabel *duanWei;
@property (weak, nonatomic) IBOutlet UILabel *rank;
@property (weak, nonatomic) IBOutlet UILabel *shengDian;
@property (weak, nonatomic) IBOutlet UILabel *time;

@end

@implementation DuanWeiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self reloadDate];
}
- (void)reloadDate
{
    NSString *daquStr = [self.qu stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
    NSString *nameStr = [self.name stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
    [YQNetWorkRequestManager requestURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://API.xunjob.cn/s5str.php?playerName=%@&serverName=%@",nameStr,daquStr]] method:YQ_GET params:nil result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//            if ([dict[@"status"] isEqual:@10401] || !dict) {
//                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"错误" message:@"输入有误" preferredStyle:UIAlertControllerStyleAlert];
//                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//                    [self.navigationController popViewControllerAnimated:YES];
//                }]];
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    [self presentViewController:alert animated:YES completion:nil];
//                });
//            }
            dispatch_async(dispatch_get_main_queue(), ^{
                self.duanWei.text = [NSString stringWithFormat:@"段位:%@",dict[@"tier"]];
                self.rank.text = [NSString stringWithFormat: @"Rank:%@",dict[@"rank"]];
                self.shengDian.text = [NSString stringWithFormat:@"胜点:%@",dict[@"league_points"]];
                self.time.text = [NSString stringWithFormat:@"更新时间:%@",dict[@"warzone_updated"]];
            });
        }
//            else{
//            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"错误" message:@"输入有误" preferredStyle:UIAlertControllerStyleAlert];
//            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//                [self.navigationController popViewControllerAnimated:YES];
//            }]];
//            dispatch_async(dispatch_get_main_queue(), ^{
//                [self presentViewController:alert animated:YES completion:nil];
//            });
//        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (IBAction)didClickButton:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}



@end
